{% extends "Sales_base.html" %}

{% block head %}
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Arial, sans-serif;
        }

        body {
            background: #f5f6fa;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        .login-container {
            background: white;
            padding: 2.5rem;
            border-radius: 12px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 400px;
        }

        .role-tabs {
            display: flex;
            margin-bottom: 2rem;
            border-bottom: 2px solid #eee;
        }

        .role-tab {
            flex: 1;
            padding: 1rem;
            text-align: center;
            cursor: pointer;
            color: #666;
            transition: all 0.3s;
            border-bottom: 2px solid transparent;
        }

        .role-tab.active {
            color: #2c7a47;
            border-bottom-color: #2c7a47;
            font-weight: 500;
        }

        .login-form {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }

        .form-group {
            position: relative;
        }

        .form-label {
            display: block;
            margin-bottom: 0.5rem;
            color: #333;
            font-size: 0.9rem;
        }

        .form-input {
            width: 100%;
            padding: 0.8rem 1rem;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            transition: border-color 0.3s;
        }

        .form-input:focus {
            border-color: #2c7a47;
            outline: none;
            box-shadow: 0 0 0 3px rgba(44,122,71,0.1);
        }

        .login-btn {
            background: #2c7a47;
            color: white;
            padding: 1rem;
            border: none;
            border-radius: 6px;
            font-size: 1rem;
            cursor: pointer;
            transition: opacity 0.3s;
        }

        .login-btn:hover {
            opacity: 0.9;
        }

        .login-btn.loading {
            opacity: 0.7;
            cursor: not-allowed;
        }

        .message {
            text-align: center;
            margin-top: 1rem;
            padding: 0.8rem;
            border-radius: 4px;
            display: none;
        }

        .success {
            background: #e8f5e9;
            color: #2c7a47;
        }

        .error {
            background: #ffebee;
            color: #e74c3c;
        }

        @media (max-width: 480px) {
            .login-container {
                margin: 1rem;
                padding: 1.5rem;
            }
        }
    </style>
{% endblock %}
{% block main%}
    <div class="login-container">
        <div class="role-tabs">
            <div class="role-tab active" data-role="seller">商家登录</div>
            <div class="role-tab" data-role="admin">管理员登录</div>
        </div>
        <form method="post" class="login-form" onsubmit="handleLogin(event)">
    {% csrf_token %}
    <!-- 新增隐藏的role字段 -->
    <input type="hidden" name="role" id="roleField" value="seller">

    <div class="form-group">
        <label class="form-label">账号</label>
        <input
            type="text"
            class="form-input"
            id="username"
            name="username"
            placeholder="请输入账号"
            required
        >
    </div>

    <div class="form-group">
        <label class="form-label">密码</label>
        <input
            type="password"
            class="form-input"
            id="password"
            name="password"
            placeholder="请输入密码"
            required
            minlength="6"
        >
    </div>

    <button type="submit" class="login-btn">立即登录</button>
    <div class="message" id="loginMessage"></div>
</form>
    </div>

    <script>

        // 当前登录类型
        let currentRole = 'seller';

        // 切换登录类型
        document.querySelectorAll('.role-tab').forEach(tab => {
        tab.addEventListener('click', function() {
            document.querySelectorAll('.role-tab').forEach(t =>
                t.classList.remove('active'));
            this.classList.add('active');
            currentRole = this.dataset.role;

            // 更新隐藏字段的值
            document.getElementById('roleField').value = currentRole;
        });
    });

    // 初始化时设置默认值
    document.getElementById('roleField').value = 'seller';



        // 显示提示信息
        function showMessage(text, type) {
            const message = document.getElementById('loginMessage');
            message.textContent = text;
            message.className = `message ${type}`;
            message.style.display = 'block';
        }


    </script>
{% endblock %}